﻿@using  Layui.Framework.Datatable
@using Layui.Entities
@model DataSourceResult<SysLog, LogSearchArg>
@{
    ViewBag.Title = "系统日志列表";
}
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="@Url.RouteUrl("mainIndex")">首页</a>
        </li>
        <li class="active">系统日志</li>
    </ul>
</div>
<div class="page-content">
    <h1>@ViewBag.Title</h1>
    <hr />
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    <form asp-route="sysLogIndex" method="get" class="form-inline">
                        <label>类型</label>
                        <select name="level" class="form-control">
                            <option value="">不限</option>
                            @foreach (var item in Enum.GetValues(typeof(EnumLevel)))
                            {
                                if ((int)item == Model.Arg.level)
                                {
                                    <option value="@((int)item)" selected="selected">@item</option>
                                }
                                else
                                {
                                    <option value="@((int)item)">@item</option>
                                }
                            }
                        </select>
                        <button type="submit" class="btn btn-purple btn-sm">
                            查询
                            <i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
                        </button>
                        <a class="btn btn-danger btn-sm" id="btnClearLog" href="@Url.RouteUrl("clearSysLog")"><i class="ace-icon fa fa-trash-o"></i>理日志</a>
                    </form>
                </div>
            </div>
        </div>
    </div>
    @if (Model != null && Model.Data != null)
    {
        <div class="row">
            <div class="col-sm-12">
                <table id="user_datatable" class="table table-striped table-bordered table-hover dataTable no-footer">
                    <thead>
                        <tr>
                            <th width="50px">类型</th>
                            <th width="150px">错误</th>
                            <th width="100px">IP地址</th>
                            <th width="">连接</th>
                            <th width="">ReferrerUrl</th>
                            <th width="160">时间</th>
                            <th width=""></th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Data)
                        {
                            <tr>
                                <td>@(Enum.GetName(typeof(EnumLevel), item.Level))</td>
                                <td>@item.ShortMessage</td>
                                <td>@item.IpAddress</td>
                                <td>@item.PageUrl</td>
                                <td>@item.ReferrerUrl</td>
                                <td>@(item.CreationTime.ToString("yyyy-MM-dd HH;mm:ss"))</td>
                                <td>
                                    <button type="button" class="btn btn-xs btn-link" data-toggle="modal" data-target="#modal_@item.Id">查看详情</button>
                                    <div class="modal fade bs-example-modal-lg" id="modal_@item.Id" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                                        <div class="modal-dialog modal-lg" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                    <h4 class="modal-title" id="gridSystemModalLabel">@item.ShortMessage</h4>
                                                </div>
                                                <div class="modal-body">
                                                    @item.FullMessage
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <pager page-value="Model.Paging"></pager>
            </div>
        </div>
    }
</div>
<script>
    $(function () {

        $('#btnClearLog').click(function (e) {
            e.preventDefault();
            var url = this.href;
            layer.confirm('您确定要清理日志？', function () {
                layer.load();
                $.get(url, function (data) {
                    layer.closeAll();
                    layer.msg(data.Message, { icon: 1 });
                });
            });
        });
    });
</script>